<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.6.10/vue.js"></script>
    <title>p13v-for循环中key属性的使用</title>
</head>
<body>
    <div id="app">
        <div>
            <label>Id:
                <input type="text" v-model="id">
            </label> 
            <label>Name:
                <input type="text" v-model="name">
            </label>
            <input type="button" @click="add" value="添加">
        </div>
        <!-- v-for循环的时候key属性只能使用number或者string -->
        <!-- 注意：key使用的时候，必须使用v-bind属性绑定的形式，指定key的值 -->
        <p v-for="item in list" :key="item.id">
            <input type="checkbox">
            {{item.id}}------{{item.name}}
        </p>
    </div>
    <script>
        var vm=new Vue({
            el:"#app",
            data:{
                id:"",
                name:"",
                list:[
                    {id:1,name:"嬴政"},
                    {id:2,name:"韩非"},
                    {id:3,name:"赵高"},
                    {id:4,name:"荀子"},
                    {id:5,name:"赵高"}
                ]
            },
            methods:{
                add(){
                    this.list.unshift({
                        id:this.id,
                        name:this.name
                    })
                }
            }
        })
    </script>
</body>
</html>